<template>
  <div class="index-container">
    <van-tabs :swipe-threshold="1" v-model="active" sticky swipeable @change="fetchList">
      <van-tab v-for="(itme, index) in subjectList" :key="index" :title="itme.name">
        <div class="mt10">
          <van-list :loading="loading" :finished="finished" finished-text="我也是有底线的" @load="onLoad">
            <div v-for="(item, index) in list" :key="index" class="pack_live_div">
              <div class="pack_live_left" @click="toTeachersInfo(item)">
                <img :src="item.avatar" class="pack_live_touxiang" />
                <div class="pack_live_right">
                  <div class="pack_live_name">
                    <i class="mr5">{{ item.name }}</i>
                    <van-icon :name="require('@/assets/images/teacher-vip.png')" />
                  </div>
                  <div class="pack_live_name1">{{ item.cert }}</div>
                  <div class="pack_live_name2">{{ item.intro }}</div>
                </div>
              </div>
            </div>
          </van-list>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import { getSubjectList } from '@/api/user'
import { getTeacherList } from '@/api/teachers'
export default {
  data() {
    return {
      active: 0,
      loading: false,
      finished: false,
      queryParams: {
        page: 1
      },
      subjectList: [],
      list: [],
      total: 1
    }
  },
  computed: {},
  mounted() {
    this.getSubject()
  },
  methods: {
    fetchList() {
      this.queryParams.cate_id = this.subjectList[this.active].id
      this.list = []
      this.finished = false
      this.queryParams.page = 1
      this.onLoad()
    },
    async onLoad() {
      this.loading = true
      await getTeacherList(this.queryParams).then(res => {
        this.list = this.list.concat(res.data.list)
        this.queryParams.page = this.queryParams.page + 1
        this.total = res.data.total
      })
      this.loading = false
      if (this.list.length >= this.total) {
        this.finished = true
      }
    },
    async getSubject() {
      await getSubjectList().then(res => {
        this.subjectList = res.data.filter(b => b.depth === 2)
        this.subjectList.unshift({ name: '全部', id: 0 })
      })
      this.queryParams.cate_id = this.subjectList[this.active].id
    },
    toTeachersInfo(row) {
      this.$router.push({ name: 'TeachersInfo', query: row })
    }
  }
}
</script>

<style lang="scss" scoped>
.index-container {
  .van-list {
    // padding: 15px;
  }
  .pack_live_div {
    box-sizing: border-box;
    margin: 0 15px 15px;
    padding: 15px;
    height: 125px;
    background: #ffffff;
    box-shadow: 0px 0px 4px 0px rgba(210, 212, 213, 0.3);
    border-radius: 5px;
    .pack_live_left {
      display: flex;
      .pack_live_touxiang {
        width: 107px;
        height: 105px;
        border-radius: 5px;
      }
      .pack_live_right {
        width: 100%;
        padding: 3px 0 0 10px;
        // border-bottom: 0.02667rem solid #ebedf0;
      }
      .pack_live_name {
        font-size: 14px;
        font-weight: 600;
        color: #009697;
        .van-icon {
          vertical-align: text-top;
        }
      }
      .pack_live_name1 {
        font-size: 14px;
        font-weight: 400;
        color: #333333;
        line-height: 38px;
      }
      .pack_live_name2 {
        font-size: 12px;
        font-weight: 400;
        color: #666666;
        line-height: 20px;
        @include textoverflow(2);
      }
    }
    .pack_live_content {
      margin-top: 16px;
      font-size: 14px;
      color: #333333;
      line-height: 22px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 3;
      -webkit-box-orient: vertical;
    }
  }
}
</style>
